package ssms.autocomplete;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.faces.application.FacesMessage;

import pagecode.PageCodeBase;

import ssms.entities.CustomerMstr;
import ssms.entities.controller.CustomerMstrManager;
 
public class CustIDList extends PageCodeBase{
    private List<String> IDs;
    private List<String> data;
    List<CustomerMstr> customers;
    List<String> names; 
    public CustIDList() {
    }
 
    public List<String> getIDs() {
    	IDs = new ArrayList<String>();
    	try {
			CustomerMstrManager customerManager = 
			(CustomerMstrManager)getManagedBean("CustomerMstrManager");
			customers = customerManager.getCustomer();
			if (customers == null) {
				throw new Exception("Unable to get customer list.");
			}
		
			for( CustomerMstr c:customers){
				IDs.add(c.getCustid());
			}
		} catch (Exception e) {
			return null;
		}
        return IDs;
    }
    
    public List<String> getNames() {
    	try {
    		names = new ArrayList<String>();
			CustomerMstrManager customerManager = 
			(CustomerMstrManager)getManagedBean("CustomerMstrManager");
			customers = customerManager.getCustomer();
			if (customers == null) {
				throw new Exception("Unable to get customer list.");
			}
		
			for( CustomerMstr c:customers){
				names.add(c.getCustname());
			}
		} catch (Exception e) {
			return null;
		}
        return names;
    }
    
    public List<String> getData(String id) {
    	try {
			CustomerMstrManager customerManager = 
			(CustomerMstrManager)getManagedBean("CustomerMstrManager");
			customers = customerManager.getCustomer();
			if (customers == null) {
				throw new Exception("Unable to get customer list.");
			}
		
			for( CustomerMstr c:customers){
				if (c.getCustid() == id)
				{
					data.add(c.getCustname());
					data.add(Integer.toString(c.getAvailablespace()));
					break;
				}
			}
		} catch (Exception e) {
			return null;
		}
        return data;
    }
}
